<html>
<head><meta charset="utf-8"><title>ConstKind::Unevaluated after typecheck · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html">ConstKind::Unevaluated after typecheck</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="191362182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191362182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191362182">(Mar 21 2020 at 19:31)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  <span class="user-mention" data-user-id="121053">@varkor</span>  should any ConstKind::Unevaluated be allowed to exist after type check?</p>
<p>This is the cause of <a href="https://github.com/rust-lang/rust/issues/70125" target="_blank" title="https://github.com/rust-lang/rust/issues/70125">https://github.com/rust-lang/rust/issues/70125</a></p>



<a name="191363645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191363645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191363645">(Mar 21 2020 at 20:10)</a>:</h4>
<p>I think what happened is: there is a const param, it is monomorphized <a href="https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L61" target="_blank" title="https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L61">here</a>. The result is a <code>ConstKind::Unevaluated</code>. This is normally handled fine when there was no previous monomorphization, but in this case there is a match case missing for unevaluated. I think you can fix this by recursively calling the current function <a href="https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L62" target="_blank" title="https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L62">here</a> instead of the if expression.</p>



<a name="191363718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191363718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191363718">(Mar 21 2020 at 20:12)</a>:</h4>
<p>And just in case replace the <code>_</code> wildcard of the match arm with <code>ConstKind::Param</code> and move the <code>bug!</code> to a new wildcard arm.</p>



<a name="191364825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191364825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191364825">(Mar 21 2020 at 20:42)</a>:</h4>
<p>thanks <span class="user-mention" data-user-id="133247">@bjorn3</span>  <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span> will try this out</p>



<a name="191415355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415355">(Mar 22 2020 at 20:49)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> ftr, <code>monomorphize</code> shouldn't leave anything unevaluated, it's pretty much its job, but there's a bug. also, repeatedly applying <code>monomorphize</code> is wrong, as it will keep substituting, but substitutions can only be meaningfully applied once</p>



<a name="191415446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415446">(Mar 22 2020 at 20:51)</a>:</h4>
<p>Where did I say that repeatedly applying <code>monomorphize</code> was a good idea?</p>



<a name="191415489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415489">(Mar 22 2020 at 20:52)</a>:</h4>
<p>you suggested recursively calling <code>eval_mir_constant</code></p>



<a name="191415494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415494">(Mar 22 2020 at 20:52)</a>:</h4>
<p>after this <code>monomorphize</code> call <a href="https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L61" target="_blank" title="https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L61">https://github.com/rust-lang/rust/blob/46f5aa93d47e9077775ad9038970fd4c77abaad7/src/librustc_codegen_ssa/mir/constant.rs#L61</a></p>



<a name="191415501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415501">(Mar 22 2020 at 20:53)</a>:</h4>
<p>which would result in <code>monomorphize</code> being applied multiple times, potentially</p>



<a name="191415556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415556">(Mar 22 2020 at 20:54)</a>:</h4>
<p>In that case the <code>monomorphize</code> should not return <code>ConstKind::Param</code>. I suggested to only apply <code>monomorphize</code> on <code>ConstKind::Param</code>.</p>



<a name="191415583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415583">(Mar 22 2020 at 20:55)</a>:</h4>
<p>anyway special-cases like that should be avoided as much as possible</p>



<a name="191415600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415600">(Mar 22 2020 at 20:55)</a>:</h4>
<p>hence my suggestion to call <code>monomorphize</code> once (irrespective of variant), and then handle <code>Unevaluated</code>, in case <code>monomorphize</code> failed to normalize for whatever reason</p>



<a name="191415708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415708">(Mar 22 2020 at 20:57)</a>:</h4>
<p>That is indeed a much better way. cg_clif also does it that way it seems: <a href="https://github.com/bjorn3/rustc_codegen_cranelift/blob/9d014d77813fd28b29d4c3fd166d429274fc94a2/src/constant.rs#L74" target="_blank" title="https://github.com/bjorn3/rustc_codegen_cranelift/blob/9d014d77813fd28b29d4c3fd166d429274fc94a2/src/constant.rs#L74">https://github.com/bjorn3/rustc_codegen_cranelift/blob/9d014d77813fd28b29d4c3fd166d429274fc94a2/src/constant.rs#L74</a></p>



<a name="191415885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191415885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191415885">(Mar 22 2020 at 21:00)</a>:</h4>
<p>monomorphize should be calling eval, it's just that nobody added a <code>fold_const</code> in the right place :(</p>



<a name="191496429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191496429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191496429">(Mar 23 2020 at 16:10)</a>:</h4>
<p>I wonder if there's a good way we can force <code>fold_const</code> to be implemented if <code>fold_ty</code> has been</p>



<a name="191500343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ConstKind%3A%3AUnevaluated%20after%20typecheck/near/191500343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ConstKind.3A.3AUnevaluated.20after.20typecheck.html#191500343">(Mar 23 2020 at 16:35)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> eh we could make them both required or something. idk</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>